package org.boge.sharpdoc.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.boge.sharpdoc.dao.DocCollectDao;
import org.boge.sharpdoc.bean.DocCollect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class DocCollectService {
    @Autowired
    private DocCollectDao docCollectDao;

    public PageInfo<DocCollect> findByUid(Integer index, Integer pageSize, Long phone) {
        return PageHelper.startPage(index, pageSize, "ctime desc").doSelectPageInfo(() -> docCollectDao.findByUid(phone));
    }

    public Integer addCollect(Long phone, Integer docid) {
        return docCollectDao.addCollect(phone, docid);
    }

    public Integer deleteCollect(Long phone, Integer docid) {
        return docCollectDao.deleteCollect(phone, docid);
    }

    public boolean isCollected(Long phone, Integer docid) {
        return docCollectDao.findIfCollected(phone, docid);
    }

    public PageInfo<DocCollect> getAllWithPage(Integer index, Integer pageSize) {
        return PageHelper.startPage(index, pageSize, "ctime desc").doSelectPageInfo(() -> docCollectDao.findAll());
    }
}